package com.zrouter.plugin

import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes

class ZRouterPluginClassVisitor extends ClassVisitor {

    //注册表的全类名集合
    private List<String> routeList

    ZRouterPluginClassVisitor(ClassVisitor cv, List<String> routeList) {
        super(Opcodes.ASM5, cv)
        this.routeList = routeList
    }

    @Override
    void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        super.visit(version, access, name, signature, superName, interfaces)
    }

    @Override
    MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions)
        if (name == "registerByPlugin") {
            mv = new ZRouterMethodVisitor(mv, routeList)
        }
        return mv
    }

    @Override
    void visitEnd() {
        super.visitEnd()
    }
}